package pl.elka.simulator.core.configurationCommand.impl;

import java.util.ArrayList;
import java.util.List;

import pl.elka.simulator.core.AreaConstraint;
import pl.elka.simulator.core.Position;
import pl.elka.simulator.core.configurationCommand.ConfigurationCommandType;
import pl.elka.simulator.core.configurationCommand.ICommandParam;
import pl.elka.simulator.core.configurationCommand.IConfigurationCommand;
import pl.elka.simulator.core.configurationCommand.ables.IAbleToAreaConstraintConfiguration;
import pl.elka.simulator.core.configurationCommand.ables.IAbleToConfiguration;
import pl.elka.simulator.core.configurationCommand.impl.param.PositionsListCommandParam;

public class AddAreaConstraintConfigurationCommand implements IConfigurationCommand{

	private ICommandParam param;
	@Override
	public IConfigurationCommand newInstance() {		
		return new AddAreaConstraintConfigurationCommand();
	}

	@Override
	public void setParam(ICommandParam param) {
		this.param = param;
	}

	@Override
	public ICommandParam getParam() {
		return param;
	}

	@Override
	public ConfigurationCommandType getType() {
		return ConfigurationCommandType.AddAreaConstraintConfigurationCommand;
	}
	@Override
	public void execute(IAbleToConfiguration able){
		IAbleToAreaConstraintConfiguration ca = (IAbleToAreaConstraintConfiguration) able;
		
		//AreaConstraint constraint = ca.getAreaConstraint();
		
		List<Position> poss = ((PositionsListCommandParam)getParam()).getPositions();		
		AreaConstraint ac = new AreaConstraint(poss);	
		
		List<Position> pos2 = new ArrayList<Position>();
		pos2.add(new Position(ac.minX,ac.maxY));
		pos2.add(new Position(ac.maxX,ac.maxY));
		pos2.add(new Position(ac.maxX,ac.minY));
		pos2.add(new Position(ac.minX,ac.minY));
		
		AreaConstraint ac2 = new AreaConstraint(pos2);	
		
		ca.setAreaConstraint(ac2);
	}
	
}
